﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WHC.Hotel.BLL;
using WHC.Hotel.Entity;
using WHC.OrderWater.Commons;


namespace WHC.Hotel.UI
{
    public partial class FrmSwitchTeaSuite : BaseForm
    {
        public TeaSuiteInfo RoomInfo = null;
        private TeaOrderInfo orderInfo = null;

        public FrmSwitchTeaSuite()
        {
            InitializeComponent();
        }

        private void FrmSwitchRoom_Load(object sender, EventArgs e)
        {
            if (RoomInfo != null)
            {
                this.lblRoomNo.Text = RoomInfo.RoomNo;
                orderInfo = BLLFactory<TeaOrder>.Instance.GetCurrentOrder(RoomInfo.RoomNo);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.None;

            #region 输入验证
            if (this.txtTarget.Text.Trim().Length == 0)
            {
                return;
            }

            TeaSuiteInfo roomInfo = BLLFactory<TeaSuite>.Instance.FindByRoomNo(this.txtTarget.Text);
            if (roomInfo == null)
            {
                MessageUtil.ShowWarning("餐台不存在，不能进行调整");
                this.txtTarget.Focus();
                return;
            }
            else if (roomInfo.Status != TeaSuiteStatus.可供)
            {
                MessageUtil.ShowWarning("餐台不是可供状态，不能进行调整");
                this.txtTarget.Focus();
                return;
            } 
            else if(orderInfo == null)
            {
                MessageUtil.ShowWarning("原餐台的订单不存在，不能进行调整");
                return;
            }
            #endregion

            try
            {
                bool result = BLLFactory<TeaOrder>.Instance.SwitchRoom(orderInfo, this.txtTarget.Text, this.chkAttachRoomMoney.Checked);
                if (!result)
                {
                    MessageUtil.ShowWarning("房间调整不成功");
                    return;
                }

                this.DialogResult = DialogResult.OK;//成功则返回
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                MessageUtil.ShowError(ex.Message);
            }
        }

    }
}
